Time and Context Intervals
TPT assessments are always calculated in a so-called context interval. The default context interval is the duration of the test case. A test case has a time from zero to the end-time of a test. This is the largest time interval of a test. For a trial, for example of 60 seconds, the largest possible time interval is 60 s.
Time intervals in the test can be calculated explicitly by using TPT.Interval(start_time,end_time)
or implicitly by evaluating timed regular expressions TPT.regexp()
or using TPT.trigger()
. All of these functions return time intervals.
In order to return context intervals, you must use the during
keyword. The during
keyword shrinks the current context interval to the length of the time interval specified by the user. This means that the context interval is a shorter interval inside a during phase. Several during
keywords can be nested.
The during
keyword runs through the intervals you have specified every time the condition you have specified becomes true. For example, when you have specified TPT.regexp([light_intensity>50]), the checks or actions in the during block are repeated every time light_switch
is greater than 50.
during TPT.Interval()
TPT.Interval(start_time, end_time)
creates a new interval that ranges from the start_time
to the end_time
. Both parameters must be specified in local time relative to the current context interval.
When nesting TPT.Interval(start_time, end_time)
, the start_time
and end_time
relate to the interval it is nested in, thus the local time of the first interval.
In the following example, the first interval stretches from second 2 to second 8 related to the global time. The interval itself, thus the local time, stretches from second 0 to second 6.
The second interval is nested into the first interval. Related to the global time, it stretches from second 4 to second 5. Related to the first interval it is nested in, it stretches from second 2 to second 3. The local time of this interval starts at second 0 and ends at second 1.
# Declare a new assessment variable that shows up in the report foo = TPT.DoubleX() my_explicit_interval = TPT.Interval(2,8) during my_explicit_interval: print "This interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this. getEndTime()),"s (global time)" # The signal foo is defined as sin(t) from second 2 to second 8. The time t is the local time starting with 0 in this interval. foo(t) := sin(t) # An interval is nested into the previous interval my_nested_interval = TPT.Interval(2,3) during my_nested_interval: print "This nested interval is from:", this.getStartTime(), "s to", this.getEndTime(), "s (local time)" print "This nested interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this. getEndTime()),"s (global time)" |
during TPT.regexp()
By using a time dependent regular expression, you can specify that checks or actions are only executed when a specified condition is true.
In the following example, whenever light_switch
is on, the first interval is set. light_switch
is on from second 1 to second 5.
The second interval is nested into the first and thus related to it concerning the time context. The condition says, it must be greater or equal to one. This way, the second interval skips the first second.
The third interval is also nested into the first interval, and so it is also related to it concerning the time context. The condition says that t must be smaller or equal to the end time of the test minus 1.
my_implicit_interval = TPT.regexp([light_switch == 1]) during my_implicit_interval: print "This interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this.getEndTime()),"s (global time)" TPT.assertAlways(headlight==1,"Assert if headlight on when switch is on.") #An interval is nested into the first interval and skips the first second during TPT.regexp([t>=1s]): print "This nested interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This nested interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this.getEndTime()),"s (global time)" #Another interval is nested into the first interval and skips the last second during TPT.regexp([t<=(this.getEndTime()-1)]): print "This nested interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This nested interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this.getEndTime()),"s (global time)" |
during TPT.trigger()
By using the TPT.trigger()
function, you can specify a start condition, a stop condition, and an abort condition.
In the following example, whenever light_intensity
is greater or equal to 50, the checks and actions following are performed. The checks and actions are no longer executed, when the light_intensity
is greater than or equal to 81, or if the global time is greater than or equal to 8 seconds.
In the test case, where this check ois performed, the checks and actions are performed two times: first between second 0.67 and second 1.81, and the second time between second 5.67 and second 7.48. It aborts the check if foo
is greater or equal to 10.
The nested TPT.trigger()
function starts the checks and actions only if the first specified TPT.trigger()
function is true and only if the light_switch
is 0. It stops, when the light_switch
is 2, or aborts the check if foo
is greater or equal to 10.
during TPT.trigger(light_intensity >= 50,light_intensity >= 81, t>=8s): print "This interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this. getEndTime()),"s (global time)" during TPT.trigger(light_switch == 0, light_switch==2, foo>=10): print "This nested interval is from:", this.getStartTime(), "s to", this. getEndTime(), "s (local time)" print "This nested interval is from:", TPT.toGlobal (this.getStartTime()), "s to", TPT.toGlobal (this.getEndTime()),"s (global time)" |
Otherwise keyword
The otherwise
keyword can only be used with a during keyword. It performs the specified assessment or actions where the during condition was not fulfilled.
Since it implicitly negates the condition of the during
, no further condition can be added.
When This behavior is checked as follows: during [light_switch == AUTO_MODE && light_intensity > 70]: TPT.assertExists(headlight == 0,"Headlight OFF"); otherwise: TPT.assertExists(headlight == 1, "Headlight ON"); To visualize what this script does, the following image was created with the condition tree feature of the Signal Viewer (see also Assesslet Types - Condition Tree). The intervals where the |